package interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Author:shixiaojun@itany.com
 * Date:2022/3/11 14:59
 * Version:1.0-SNAPSHOT
 */
public class LogInterceptor implements HandlerInterceptor {

    /**
     * 在进入Handler业务方法之前处理
     * @param request
     * @param response
     * @param handler
     * @return  用于判断是否进入Handler,true-进入,false-不进入
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        System.out.println("LogInterceptor.preHandle");
        return true;
    }

    /**
     * 在执行完成Handler业务方法之后处理
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
        System.out.println("LogInterceptor.postHandle");
    }

    /**
     * 在响应到达之前处理
     * @param request
     * @param response
     * @param handler
     * @param ex
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        System.out.println("LogInterceptor.afterCompletion");
    }
}
